package cn.belong.jk.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.belong.jk.entity.ExtCproduct;
import cn.belong.jk.entity.Factory;
import cn.belong.jk.entity.SysCode;
import cn.belong.jk.service.ExtCproductService;
import cn.belong.jk.service.FactoryService;

@Controller
@RequestMapping("extcproduct")
public class ExtCproductController extends BaseController {

	@Resource
	ExtCproductService extCproductService;
	@Resource
	FactoryService factoryService;
	
	//转向新增页面  
	@RequestMapping("/tocreate.action")  
	public String tocreate(String contractProductId,Model model){  
	    //传递购销合同Id  
	    model.addAttribute("contractProductId", contractProductId);  
	      
	    //准备生产厂家的下拉列表  
	    List<Factory> factoryList=factoryService.getFactoryList();  
	    model.addAttribute("factoryList",factoryList);  
	      
	    //某个货物下的附件  
	    Map<String,String> paraMap=new HashMap<String,String>();  
	    paraMap.put("contractProductId", contractProductId);  
	    List<ExtCproduct> dataList=extCproductService.find(paraMap);  
	    model.addAttribute("dataList", dataList);  
	      
	    //准备分类下拉列表  
	    List<SysCode> ctypeList=extCproductService.getCtypeList();  
	    model.addAttribute("ctypeList", ctypeList);  
	      
	    return "/cargo/contract/jExtCproductCreate.jsp";//货物的新增页面  
	}  
	
	@RequestMapping("/insert.action")
	public String insert(ExtCproduct extCproduct, Model model){
		extCproductService.insert(extCproduct);
		model.addAttribute("contractProductId", extCproduct.getContractProductId());		//传递主表ID
		
		return "redirect:/extcproduct/tocreate.action";
	}
	  
	//转向修改页面  
	@RequestMapping("/toupdate.action")  
	public String toupdate(String id,Model model){  
	    ExtCproduct obj=extCproductService.get(id);  
	    model.addAttribute("obj", obj);  
	      
	    //准备生产厂家的下拉列表  
	    List<Factory> factoryList=factoryService.getFactoryList();  
	    model.addAttribute("factoryList",factoryList);  
	      
	    //准备分类下拉列表  
	    List<SysCode> ctypeList=extCproductService.getCtypeList();  
	    model.addAttribute("ctypeList", ctypeList);  
	      
	    return "/cargo/contract/jExtCproductUpdate.jsp";//货物的修改页面  
	}  
	
	@RequestMapping("/update.action")
	public String update(ExtCproduct extCproduct, Model model){
		extCproductService.update(extCproduct);
		model.addAttribute("contractProductId", extCproduct.getContractProductId());		//传递主表ID
		
		return "redirect:/extcproduct/tocreate.action";
	}
	
	@RequestMapping("/deleteById.action")
	public String deleteById(String id, String contractProductId, Model model){
		extCproductService.deleteById(id);
		model.addAttribute("contractProductId", contractProductId);		//传递主表ID
		
		return "redirect:/extcproduct/tocreate.action";
	}
}
